package com.cristina.attention.rest;

import com.cristina.attention.entity.Friend;
import com.cristina.attention.entity.vo.AddFriendVo;
import com.cristina.attention.service.FriendService;
import com.cristina.attention.mp.support.Condition;
import com.cristina.attention.utils.Func;
import com.cristina.attention.utils.R;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Author superman
 * @Date 2021/11/13 18:51
 **/
@Slf4j
@RestController
@RequestMapping("core/friend")
@AllArgsConstructor
public class FriendController {

    private final FriendService friendService;

    /**
     * 查询单条
     */
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/detail")
    public R<Object> detail(Friend friend) {
        Friend detail = friendService.getOne(Condition.getQueryWrapper(friend));
        return R.data(detail);
    }

    /**
     * 查询单条
     */
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/info")
    public R<Object> info(Friend friend) {
        Friend detail = friendService.getById(friend.getId());
        return R.data(detail);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R<Object> list() {
        return R.data(friendService.list());
    }

    /**
     * 新增或修改
     */
    @ApiOperation(value = "新增或修改", notes = "传入friend")
    @PostMapping("/submit")
    public R<Object> submit(@RequestBody Friend friend) {
        return R.status(friendService.save(friend));
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改", notes = "传入friend")
    @PostMapping("/update")
    public R<Object> update(@RequestBody Friend friend) {
        return R.status(friendService.updateById(friend));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除", notes = "传入messageId")
    @PostMapping("/remove")
    public R<Object> remove(@PathVariable String messageId) {
        return R.status(friendService.deleteLogic(Func.toLongList(messageId)));
    }

    /**
     * 查询
     * @param originId
     * @return
     */
    @ApiOperation(value = "查询用户所拥有的好友", notes = "传入originId")
    @GetMapping("/findFriendBelonging/{originId}")
    public R<Object> findFriendBelonging(@PathVariable Long originId) {
        return R.data(friendService.findFriendBelonging(originId));
    }

    /**
     * 添加好友
     * @param addFriendVo
     * @return
     */
    @ApiOperation(value = "添加好友", notes = "传入addFriendVo")
    @PostMapping("/addFriend")
    public R<Object> addFriend(@RequestBody AddFriendVo addFriendVo) {
        return R.status(friendService.addFriend(addFriendVo));
    }

}
